<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>证照申请详情</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="applyCard" v-if="detail">
          <p class="apply-detail-title-ne">
            <el-link :type="statusJson[detail.status].type">{{ statusJson[detail.status].name }}{{detail.status==1?',待确认借出':''}}</el-link>
            <span v-if="detail.status==2">(驳回理由：{{ detail.content }})</span>
          </p>
          <div class="apply-detail-user">
            <div class="apply-detail-user-list">
              <span>证照名称:</span>
              <span>{{ detail.licence.name }}</span>
            </div>
            <div class="apply-detail-user-list">
              <span>申请时间:</span>
              <span>{{ detail.create_time }}</span>
            </div>
            <div class="apply-detail-user-list">
              <span>申请人:</span>
              <span>{{ detail.user ? detail.user.realname : '--' }}</span>
            </div>
            <div class="apply-detail-user-list">
              <span>当前持有人:</span>
              <span>{{ detail.licence.inuser ? detail.licence.inuser.realname : '--' }}</span>
            </div>
            <div class="apply-detail-user-list">
              <span>预借用时间:</span>
              <span>{{ detail.time }}</span>
            </div>
            <div class="apply-detail-user-list">
              <span>预归还时间:</span>
              <span>{{ detail.return_time }}</span>
            </div>
            <div class="apply-detail-user-list" v-if="detail.status>0">
              <span>审核人:</span>
              <span>
                {{ detail.examine ? detail.examine.realname : '' }}
              </span>
            </div>
            <div class="apply-detail-user-list" v-if="detail.status>0">
              <span>审核时间:</span>
              <span>
                {{ detail.examine_time }}
              </span>
            </div>
            <div class="apply-detail-user-list" v-if="detail.status>2">
              <span>借出时间:</span>
              <span>
                {{ detail.receive_time }}
              </span>
            </div>
            <div class="apply-detail-user-list" v-if="detail.status==4">
              <span>实际归还时间:</span>
              <span>
                {{ detail.actual_return_time }}
              </span>
            </div>
            <div class="apply-detail-user-list" v-if="detail.status==4">
              <span>归还照片:</span>
              <span v-if="detail.return_pic">
                <ImagePreview :src="detail.return_pic" width="40px" height="40px"></ImagePreview>
              </span>
              <span v-else>无</span>
            </div>
          </div>
          <div class="remark-line">
            <div class="remark-line-list">
              <span>用途:</span>
              <span>{{ detail.purpose }}</span>
            </div>
            <div class="remark-line-list">
              <span>补充说明:</span>
              <span>{{ detail.remark }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">返回</el-button>
        <el-button plain type="primary" size="small" v-if="detail && detail.status==0 && pageType!=='my'"
                   @click="examinBtn(1)">
          通过
        </el-button>
        <el-button size="small" @click="examinBtn(2)" class="ml-10" v-if="canExamine && detail && detail.status==0 && pageType!=='my'" plain type="danger">驳回
        </el-button>
        <el-button plain type="primary" size="small" v-if="canExamine && detail && detail.status==1 && pageType!=='my'" @click="examinBtn(3)">
          确认借出
        </el-button>
        <el-button size="small" @click="examinBtn(4)" class="ml-10" v-if="canExamine && detail && detail.status==3 && pageType!=='my'">
          确认归还
        </el-button>
        <el-button size="small" @click="examinBtn(5)" class="ml-10" v-if="canExamine && detail && detail.status==3 && pageType!=='my'">
          提醒归还
        </el-button>
      </div>
    </div>
    <borrowOut :visible.sync="detailVisible" @uploadPage="uploadPage" :useId="detailId"></borrowOut>
  </div>
</template>

<script>
import {licence_apply_detail} from '@/api/admin/badge';
import borrowOut from '../licence/borrowOut'
import {mapGetters} from "vuex";

export default {
  props: ['visible', 'detailId', 'pageType', 'intype'], // recruitmentType examine 审核
  components: {borrowOut},
  data() {
    return {
      dialogVisible: false,
      detail: null,
      detailVisible: false,
      canExamine: false,
      statusJson: {
        0: {
          name: '待审核',
          type: 'warning'
        },
        1: {
          name: '审核通过',
          type: 'success'
        },
        2: {
          name: '审核驳回',
          type: 'danger'
        },
        3: {
          name: '待归还',
          type: 'warning'
        },
        4: {
          name: '已归还',
          type: 'success'
        }
      }
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.initFn()
      } else {
        this.detail = ''
      }
    }
  },
  created() {
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  mounted() {
  },
  methods: {
    examinBtn(type) {
      let that = this;
      if (type === 1) {
        this.$confirm('确认证照的审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.subimitExamin(type)
        }).catch(() => {

        });
      } else if(type===2){
        this.$prompt('输入驳回说明', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(({value}) => {
          // value
          that.subimitExamin(type, value)
        }).catch(() => {

        });
      }else if (type === 3) {
        this.$confirm('确认借出证照, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          that.lendLicence()
        }).catch(() => {
        });
      } else if (type === 4) {
        this.useType = type;
        this.detailVisible = true
      } else if (type === 5) {
        // 提醒归还
        this.remindLicence()
      }
    },
    subimitExamin(type, value) {
      let n = this;
      let option = {id: this.detailId, type: type}
      if (type === 2) {
        option.content = value;
      }
      this.$post(this.api.licence.examine, option).then((response) => {
        if (response.code === 0) {
          n.initFn()
          n.$emit('InitFn')
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 提醒归还
    async remindLicence() {
      let data = await this.$post(this.api.licence.remind, {id: this.detailId});
      if (!data.code) {
        this.$message.success('提醒成功！')
      }
    },
    // 借出
    async lendLicence() {
      let data = await this.$post(this.api.licence.receive, {id: this.detailId});
      if (!data.code) {
        this.initFn()
        this.$emit('InitFn')
      }
    },
    initFn() {
      licence_apply_detail({id: this.detailId}).then(res => {
        if(res.vo.licence && Number(this.userInfo.id)===Number(res.vo.licence.user_id)){
          this.canExamine = true
        }else{
          this.canExamine = false
        }
        this.detail = res.vo
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    uploadPage(){
      this.initFn()
      this.$emit('InitFn')
    }
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 650px;
  height: 550px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}


.jobTime span {
  padding: 0 10px;
}

.apply-detail img {
  margin-right: 20px;
}

.apply-detail img:last-child {
  margin-right: 0;
}

.applyCard .apply-detail-user {
  overflow: hidden;
  padding: 0;
}

.applyCard .apply-detail-user-list {
  width: 50%;
  float: left;
  border-right: 1px solid #ddd;
  padding: 0 10px;
}

.applyCard .apply-detail-user-list:nth-child(2n) {
  border-right: none;
}

.applyCard .apply-detail-user-list span:first-child {
  width: 100px;
}

.remark-line {
  display: flex;
  border-style: none solid solid solid;
  border-color: #ddd;
  border-width: 1px;
}

.remark-line-list {
  flex: 1;
  display: flex;
  min-height: 40px;
  padding: 10px;
  box-sizing: border-box;
}

.remark-line-list:first-child {
  border-right: 1px solid #ddd;
}

.remark-line-list span:first-child {
  display: block;
  width: 100px;

}

.remark-line-list span:last-child {
  display: block;
  flex: 1;
}
.apply-detail-title-ne{
  text-align: center;
}
.apply-detail-title-ne span{
  font-size: 18px;
}
</style>
